const tel=$("#tel");
const pwd=$("#upwd");
const name=$("#username");
const newpwd=$("#newpwd");
const rnewpwd=$("#rnewpwd");
const SUError=$("#SUError");

$("#btn01").click(function () {
    $(".changeable").removeAttr("readonly");
    $(".changeable").css("background-color", "white")
})
$("#btn02").click(function () {
    if(name.val()===""){
        name.addClass("input change");
        name.attr("placeholder","用户名不能为空!");
        return;
    }
    if (pwd.val() ==="") {
        pwd.addClass("input change");
        pwd.attr("placeholder", "密码不能为空!");
        return;
    }
    if(newpwd.val()!=="") {
        if(rnewpwd.val()===""){
            rnewpwd.addClass("input change");
            rnewpwd.attr("placeholder","重复密码为空!");
            return;
        }
    }
    if(rnewpwd.val()!==""&&newpwd.val()!==""){
        if(rnewpwd.val()!==newpwd.val()){
            rnewpwd.val(null)
            rnewpwd.addClass("input change");
            rnewpwd.attr("placeholder","两次密码不一致!");
            return;
        }
        // const reg=/^(?=.*?[a-zA-Z])(?=.*?\d)[a-zA-Z\d]{7,15}$/
        // if (!reg.test($("#newpwd").val())){
        //     $("#newpwd").val(null);
        //     $("#rnewpwd").val(null);
        //     $("#newpwd").addClass("input change");
        //     $("#newpwd").attr("placeholder","");
        //     return;
        // }
    }

    $.ajax({
        url: "/users/UpUserInfo",
        type: "post",
        data: {
            tel: tel.val(),
            name:name.val(),
            pwd: pwd.val(),
            newpwd:newpwd.val(),
        },
        success: function (Result) {
            alert(Result.msg)
            if (Result.code === 20031) {
                window.location.href="/users/userinfo";
            }
        },
        error: function () {
            alert("修改信息错误，系统忙！");
        }
    });

})